package org.shunfeng.controller;

import org.shunfeng.pojo.Delivery;
import org.shunfeng.pojo.SysUser;
import org.shunfeng.service.DeliveryListService;
import org.shunfeng.service.impl.DeliveryListServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/delivery/editDelivery")
public class EditDelivery extends HttpServlet {
    private DeliveryListService deliveryListService = new DeliveryListServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            resp.setContentType("text/html;charset=utf-8");
//            SysUser sysUser = (SysUser)req.getSession().getAttribute("user");
//            Integer id = sysUser.getId();
            String id = req.getParameter("id");

            Delivery delivery = deliveryListService.getUserByDeliveryId(Integer.valueOf(id));

            req.setAttribute("delivery", delivery);
            req.getRequestDispatcher("/edit.jsp").forward(req,resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
